package com.envper.security.filter;//package com.yanmeng.security.filter;
//
//import com.alibaba.fastjson2.JSON;
//import com.yanmeng.common.constant.Constants;
//import com.yanmeng.common.domain.dto.LoginRequestDTO;
//import com.yanmeng.common.utils.RedisUtils;
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.ServletInputStream;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import lombok.RequiredArgsConstructor;
//import org.jetbrains.annotations.NotNull;
//import org.springframework.stereotype.Component;
//import org.springframework.util.ObjectUtils;
//import org.springframework.util.StringUtils;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import java.io.IOException;
//
//@Component
//@RequiredArgsConstructor
//public class CaptchaValidationFilter extends OncePerRequestFilter {
//
//    public static final String CAPTCHA_CODE_PARAM_NAME = "captchaCode";
//    public static final String CAPTCHA_KEY_PARAM_NAME = "captchaKey";
//    private final RedisUtils redisUtils;
//
//    @Override
//    protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) throws ServletException, IOException {
//        ServletInputStream inputStream = request.getInputStream();
//        byte[] bytes = inputStream.readAllBytes();
//        LoginRequestDTO loginRequestDTO = JSON.parseObject(bytes, LoginRequestDTO.class);
//        if(ObjectUtils.isEmpty(loginRequestDTO)){
//            filterChain.doFilter(request, response);
//            return;
//        }
//        String captchaCode = loginRequestDTO.getCaptchaCode();
//        String captchaKey = loginRequestDTO.getCaptchaKey();
//         String captchaVerifyCode = (String) redisUtils.getCacheObject(Constants.CAPTCHA + captchaKey);
//        if(StringUtils.hasLength(captchaVerifyCode)){
//            System.out.println("captchaVerifyCode = " + captchaVerifyCode);
//            if(captchaVerifyCode.equalsIgnoreCase(captchaCode)){
//
//            }else{
//
//            }
//        }
//        filterChain.doFilter(request, response);
//    }
//}